package com.lzh.o2o.web.frontend;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lzh.o2o.pojo.HeadLine;
import com.lzh.o2o.pojo.ShopCategory;
import com.lzh.o2o.service.HeadLineService;
import com.lzh.o2o.service.ShopCategoryService;
import com.lzh.o2o.web.superadmin.AreaController;

/** 
* @author  haohao: 
* @date 创建时间：2018年9月19日 下午3:54:59 
* @version 1.0 
* @parameter 
* @since  
* @return  
*/
@Controller
@RequestMapping("/frontend")
public class MainPageController {
	@Autowired
	private ShopCategoryService shopCategoryService;
	
	@Autowired
	private HeadLineService headLineService;
	Logger logger=LoggerFactory.getLogger(MainPageController.class);

	//获取头条信息用于前端展示
	@RequestMapping(value="/listmainpageinfo",method=RequestMethod.GET)
	@ResponseBody
	private Map<String,Object>listMainPageInfo(){
		Map<String,Object> modelMap = new HashMap<String,Object>();
		logger.info("查询头条信息方法开始");
		List<ShopCategory> shopCategoryList = new ArrayList<ShopCategory>();
		try{
			//获取一级店铺类别列表（即parentId为空的ShopCategory）
			shopCategoryList =  shopCategoryService.getShopCategoryList(null);
			modelMap.put("shopCategoryList", shopCategoryList);
		}catch(Exception e){
			logger.error("查询一级店铺类别异常");
			modelMap.put("success", false);
			modelMap.put("errMsg", e.getMessage());
			return modelMap;
		}
		
		List<HeadLine> headLineList = new ArrayList<HeadLine>();
		try{
			//获取状态为可用(1)的头条列表
			HeadLine headLineCondition = new HeadLine();
			headLineCondition.setEnableStatus(1);
			//根据查询条件查询头条信息列表
			headLineList= headLineService.getHeadLineList(headLineCondition);
			modelMap.put("headLineList", headLineList);
		}catch(Exception e){
			logger.error("获取头条信息列表失败");
			modelMap.put("success", false);
			modelMap.put("errMsg", e.getMessage());
			return modelMap;
		}
		logger.info("获取头条信息列表成功");
		modelMap.put("success", true);
		return modelMap;
		
	}
}
